/**  
* @Title: BlogCtrl.java 
* @Description:
* @Copyright: Copyright (c) 2018
* @Company:http://www.sinocon.cn
* @author Administrator  
* @date 2018年3月27日  
* @version 1.0  
*/
package com.yuanlinsu.project.blog.ctrl;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yuanlinsu.common.Canstant;
import com.yuanlinsu.common.MapUtil;
import com.yuanlinsu.project.blog.entity.Blog;
import com.yuanlinsu.project.blog.service.IBlogService;
import com.yuanlinsu.project.system.annotation.Access;

/**
 * @Title: BlogCtrl
 * @Description:
 * @author:Administrator
 * @date 2018年3月27日
 */
@RestController
@RequestMapping("/b")
public class BlogCtrl {
	private @Autowired IBlogService blogService;

	@PostMapping(value = { "/{uid}" })
	public List<Blog> loadBlog(@PathVariable("uid") String u, HttpServletRequest request)
			throws UnsupportedEncodingException {
		Map<String, Object> paramMapForRequest = MapUtil.getParamMapForRequest(request);
		return this.blogService.getBlogByUser(u, paramMapForRequest);
	}

	@GetMapping(value = { "/{uid}/{page}/{pageSize}" })
	public List<Blog> loadBlog(@PathVariable("uid") String u, @PathVariable("page") Integer page,
			@PathVariable("pageSize") Integer pageSize) {
		Map<String, Object> argmap = new HashMap<String, Object>();
		argmap.put(Canstant.PAGE, page);
		argmap.put(Canstant.PAGESIZE, pageSize);
		return this.blogService.getBlogByUser(u, argmap);
	}

	@PostMapping(value = { "/add" })
	@Access(login = true)
	public Blog addBlog(Blog blog) {
		return this.blogService.addBlog(blog);
	}

}
